﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class VictoryFieldSetting : MonoBehaviour 
{

	public Camera						CameraLink = null;
	public GrayscaleEffect				GrayScaleEffectLink = null;
	public DefaultScreenFader			FaderLink = null;
	public MonoBehaviour						PPEffectLink = null;

	//	스틸 컷 촬영용 모듈들
	//	public ScreenQuad					ScreenQuadLink = null;
	//	public VictoryPhoto					VictoryPhotoLink = null;
	//	public Transform[] HiddenWhenPhotoMode = null;

	//public Transform[]					BigUnitDummyPosArray = null;
	public Transform[]					MiddleUnitDummyPosArray = null;
	//public Transform[]					SmallUnitDummyPosArray = null;	

	IEventlinePlayer					mCamTakePlayer = null;
	string								mCameraAniTakeName = "camera_result01";

	public void PlayFadeIn()
	{		
		if( this.FaderLink != null )
		{			
			this.FaderLink.FadeIn( 0.2f );
		}
		
	}
	public void PlayFadeOut()
	{
		
		if ( this.FaderLink != null )
		{
			this.FaderLink.FadeOut ( 0.3f );
		}		
	}

	public void RunScreenFX( bool bOK )
	{		
		if( bOK == true )
		{
			if( this.PPEffectLink == null )
			{
				if( this.GrayScaleEffectLink != null )
					this.GrayScaleEffectLink.enabled = true;
			}
			else
			{
				this.PPEffectLink.enabled = true;
				if( this.GrayScaleEffectLink != null )
					this.GrayScaleEffectLink.enabled = false;
			}		
		}
		else
		{
			if( this.PPEffectLink != null )
				this.PPEffectLink.enabled = false;
			if( this.GrayScaleEffectLink != null )
				this.GrayScaleEffectLink.enabled = false;
		}
		//victory_setting.ChangeToPhoto();
	}



	
	public void PlayCameraAni()
	{
		EventlineTake eve_take = Eventline.LoadTake( this.mCameraAniTakeName );
		if( eve_take == null )
		{
			Debug.LogError( "Not found camera ani : " + this.mCameraAniTakeName );
			return;
		}
		float rLength = (float)eve_take.NumFrames / (float)eve_take.FrameRate;	
		Object[] camActor = {(Object)this.CameraLink.transform.parent.gameObject};
		//Object[] camActor = { (Object)this.CameraLink.gameObject };
		this.mCamTakePlayer = Eventline.Play( eve_take, camActor, null );
	}


	//	승리 포즈 애니의 최대 길이를 리턴
	public float PlaceCharacter( ref List< BattlePawn > playerList )
	{		
		float rMaxAniTime = 0.0f;
		
		for ( int i = 0; i < this.MiddleUnitDummyPosArray.Length; ++i )
		{
			Transform t_target = this.MiddleUnitDummyPosArray[ i ];
			BattlePawn b_pawn = playerList[ i ];
			if ( b_pawn == null )
				continue;			
			b_pawn.pawnManifest.transform.position = t_target.position;
			b_pawn.pawnManifest.transform.rotation = t_target.rotation;
			RuntimeMeshChanger mesh_changer = b_pawn.pawnManifest.GetRuntimeMeshChanger ();
			if ( mesh_changer != null )
				mesh_changer.ChangeToHigh ();

//			float rAniTime = b_pawn.pawnManifest.PlayVictory ();
//			if ( rAniTime > rMaxAniTime )
//				rMaxAniTime = rAniTime;
		}
		
		return rMaxAniTime;
	}



	/*
	public void ChangeToPhoto()
	{

		if( this.HiddenWhenPhotoMode != null )
		{
			for( int i = 0;		i < this.HiddenWhenPhotoMode.Length;		++i )
			{
				Transform t = this.HiddenWhenPhotoMode[ i ];
				if( t == null )
					continue;				
				t.gameObject.SetActive( false );
			}
		}

		if( this.VictoryPhotoLink != null )
		{
			this.VictoryPhotoLink.Capture();
		}
	}
	 */
	
}
